package cn.js.ccit.flowersmall.goldCoin.service.impl;

import cn.js.ccit.common.dubbo.GoldCoinService;
import cn.js.ccit.flowersmall.goldCoin.entity.GLDDetailEntity;
import cn.js.ccit.flowersmall.goldCoin.entity.GLDUserEntity;
import cn.js.ccit.flowersmall.goldCoin.mapper.GLDDetailMapper;
import cn.js.ccit.flowersmall.goldCoin.mapper.GLDUserMapper;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.sql.Date;

/**
 * 商品购买被调用的service
 */
@DubboService
public class GoldCoinServiceImpl implements GoldCoinService {
    @Resource
    GLDDetailMapper detailMapper;
    @Resource
    GLDUserMapper userMapper;

    @Override
    public void updateGoldCoin(String userName, Integer goldCoin, String orderNo) {
        GLDDetailEntity entity = new GLDDetailEntity();
        entity.setUserName(userName);
        entity.setGoldCoin(goldCoin);
        entity.setOrderNo(orderNo);
        GLDUserEntity goldCoinuser = userMapper.getGLDByUserName(entity.getUserName());
        if (goldCoinuser==null){//没有找到用户(gift没有该逻辑)
            userMapper.addGoldCoin(entity);
        }else {
            userMapper.updateGoldCoin(entity);
        }
        entity.setCreateTime(new Date(System.currentTimeMillis()));
        detailMapper.addGoldCoin(entity);
    }
}
